package mammuthus.slave

import java.io.FileWriter

/**
 * 4/26/15 WilliamZhu(allwefantasy@gmail.com)
 */
trait TFileWriter {
  def using[A <: {def close() : Unit}, B](param: A)(f: A => B): B =
    try {
      f(param)
    } finally {
      param.close()
    }

  def writeToFile(fileName: String, data: String) =
    using(new FileWriter(fileName)) {
      fileWriter => fileWriter.append(data)
    }
}
